#include <REGX52.H>
#include "Delay.h"
#include "Key.h"
#include "Timer0.h"
#include "NiXie.h"


sbit Motor = P1^0;


unsigned char KeyNum,Compare;


void main()
{
	unsigned char Speed = 0;
	Timer0_Init();
	while(1)
	{
		KeyNum = Key();
		if (1 == KeyNum)
		{
			Compare = 0;
			Speed = 0;
		}
		if (2 == KeyNum)
		{
			Compare = 45;
			Speed = 1;
		}
		if (3 == KeyNum)
		{
			Compare = 70;
			Speed = 2;
		}
		if (4 == KeyNum)
		{
			Compare = 100;
			Speed = 3;
		}
		NiXie(1,Speed);
		
	}
}


void Timer0_Rountine() interrupt 1
{	
	static unsigned int T0CountKey = 0;	//按键扫描
	static unsigned int T0Count = 0;	//PWM
	
	TL0 = 0xA4;		//设置定时初值
	TH0 = 0xFF;		//设置定时初值
	
	T0CountKey++;	
	if (T0CountKey >= 200)
	{
		T0CountKey = 0;
		
	}
	
	T0Count++;
	T0Count %= 100;
	if (T0Count < Compare)
	{
		Motor = 1;
	}
	else
	{
		Motor = 0;
	}
}





















